/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.database.sql_generator;

import com.domain.Beberage;
import com.database.DatabaseTableProjectionGenerator;
import com.database.tables.BeberagesTable;

/**
 *
 * @author Miguel
 */
public class BeberageSQLGenerator extends SQLStatementGenerator<Beberage>{

    public BeberageSQLGenerator(String inDBTable){
        super(inDBTable);
    }
    
    @Override
    public String createSelectStatement(DatabaseTableProjectionGenerator tableProjection, String condition) {
        String selectStatement = "SELECT " + tableProjection.getTableProjection() + " ";
        selectStatement += "FROM " + getDatabaseTable() + " ";
        selectStatement += condition == null ? ";" : "WHERE " + condition + ";--";
        return selectStatement;
    }

    @Override
    public String createUpdateStatement(Beberage prevObject, Beberage newObject) {
        String updateStatement = "UPDATE " + getDatabaseTable() + " ";
        updateStatement += "SET " + BeberagesTable.BEBERAGE_DESCR_COL + " = '" + newObject.getDescription()+"',";
        updateStatement += BeberagesTable.BEBERAGE_IMAGE_PATH_COL + " = '" + newObject.getImagePath() + "' ";
        updateStatement += "WHERE " + BeberagesTable.ID_COL + " = " + prevObject.getID() + ";--";
        return updateStatement;
    }

    @Override
    public String createDeleteStatement(Beberage deletingObject) {
        String deleteStatement = "DELETE FROM " + getDatabaseTable() + " ";
        deleteStatement += "WHERE " + BeberagesTable.ID_COL + " = " + deletingObject.getID() + ";--";
        return deleteStatement;
    }

    @Override
    public String createInsertStatement(Beberage insertingObject) {
        String insertStatement = "INSERT INTO " + getDatabaseTable() + " ";
        insertStatement += "(nextval('Beberage_ID_Sequence')," + BeberagesTable.BEBERAGE_NAME_COL + ",";
        insertStatement += BeberagesTable.BEBERAGE_DESCR_COL + "," + BeberagesTable.BEBERAGE_IMAGE_PATH_COL +")";
        insertStatement += "values('" + insertingObject.getName() + "','" + insertingObject.getDescription() +"','";
        insertStatement += insertingObject.getImagePath() + "');--";
        return insertStatement;
    }
}
